{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-07-06T11:53:03.665753Z",
     "start_time": "2025-07-06T11:53:03.662205Z"
    }
   },
   "source": [
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "from pathlib import Path\n",
    "import datetime"
   ],
   "outputs": [],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-06T12:35:52.582617Z",
     "start_time": "2025-07-06T12:35:47.237914Z"
    }
   },
   "cell_type": "code",
   "source": [
    "symbol_1 = 'FILUSDT'\n",
    "symbol_2 = 'XLMUSDT'\n",
    "\n",
    "exchange = 'binance'\n",
    "data_path = Path.cwd().parent / \"data\" / exchange / \"full_data\"\n",
    "\n",
    "mkt_1 = pd.read_csv(data_path / f'{symbol_1}-spot.csv' )\n",
    "mkt_2 = pd.read_csv(data_path / f'{symbol_2}-spot.csv' )\n",
    "\n",
    "mkt_1['datetime'] = pd.to_datetime(mkt_1['datetime']).dt.tz_localize(None)\n",
    "mkt_1.set_index('datetime', inplace=True)\n",
    "mkt_1 = mkt_1.sort_index()\n",
    "\n",
    "mkt_2['datetime'] = pd.to_datetime(mkt_2['datetime']).dt.tz_localize(None)\n",
    "mkt_2.set_index('datetime', inplace=True)\n",
    "mkt_2 = mkt_2.sort_index()\n"
   ],
   "id": "ff28729c8d170659",
   "outputs": [],
   "execution_count": 29
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-06T12:40:34.226886Z",
     "start_time": "2025-07-06T12:40:34.200497Z"
    }
   },
   "cell_type": "code",
   "source": [
    "begin = datetime.datetime(2025, 1, 1)\n",
    "end = datetime.datetime(2025, 5, 31)\n",
    "\n",
    "mkt_slice_1 = mkt_1[begin:end].copy()\n",
    "mkt_slice_2 = mkt_2[begin:end].copy()\n",
    "\n",
    "ratio = pd.DataFrame(mkt_slice_1.close/mkt_slice_2.close)\n"
   ],
   "id": "a47dfec5d4ef4976",
   "outputs": [],
   "execution_count": 32
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-07-06T12:54:56.666796Z",
     "start_time": "2025-07-06T12:54:56.646559Z"
    }
   },
   "cell_type": "code",
   "source": [
    "window = 20\n",
    "period = '1d'\n",
    "ratio = ratio.resample(period).first()\n",
    "# ratio['datetime'] = ratio['datetime'].resample(period).first()\n",
    "ratio['close'] = ratio['close'].resample(period).last()\n",
    "\n",
    "ratio['volatility'] = ratio['close'].rolling(window=window).std()/np.sqrt(window)\n",
    "\n",
    "ratio['smooth_vol'] = ratio['volatility'].rolling(window=20).mean()"
   ],
   "id": "3c4219c5a06a4d65",
   "outputs": [],
   "execution_count": 39
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "66941204cb12972e"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
